<?php

namespace Admin\Controller;

use Utuo\BackgroundController;

class IndexController extends BackgroundController {
	// 初始化
	public function _initialize() {
		$this->setControllerTitle('后台首页');
		$this->setActionTitle('home', '欢迎页面');
	}
	
	// 后台首页
	public function indexAction() {
		// 顶级菜单
		$topMenu = M('menu')->where('pid=0 AND is_deleted=0')->order('sort')->select();
		// 快捷菜单
		$shortcutMenu = M('menu')->where('pid=1 AND is_deleted=0')->order('sort')->select();
		$this->assign('shortcutMenu', $shortcutMenu);
		$this->assign('topMenu', $topMenu);
		layout('layout');
		$this->display();
	}
	
	// 获取子菜单
	public function getSubMenuAction() {
		$pid = I('pid', 0, 'intval');
		$subMenu = M('menu')->where(array(
				'pid' => $pid,
				'is_deleted' => 0
		))->order('sort')->select();
		if ($subMenu){
			$this->ajaxSuccess('获取成功',$subMenu);
		} else {
			$this->ajaxError('没有子菜单');
		}
	}
	
	// 内容首页
	public function homeAction() {
		$this->display();
	}
	
}